<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<html>
	<head>
		<title>My JSP 'updateExpressStyle.jsp' starting page</title>
		<script type="text/javascript">
			function valNumber(tempNumber){
		
		  var rex_one="^[1-9]+(.[0-9]{0,2})?$";
		  var result_one =tempNumber.match(rex_one);
		  if(result_one==null){
		    return false;
		  }
	   	   return true;
		}
	function widthHeight() {
		var tempWidth = "${expressStyle.remarks}";
		var tempString = tempWidth.split("*");
		for ( var i = 0; i < tempString.length; i++) {
			if (i == 0) {
				var width = tempString[i];
			
				width=width/100;
				$("#expressWidth").val(width);
			} else if (i == 1) {
				var height = tempString[i];
				height=height/100;
				$("#expressHeight").val(height);
			}
		}
	}
</script>
	</head>
	<body>
	<section class="content">
	<div class="row">
		<div class="col-md-12">
		<div class="box box-solid box-primary">
					<div class="box-header">

						<h3 class="box-title">${titlePage}</h3>
						<div class="box-tools pull-right">
							<button class="btn btn-primary btn-sm" data-widget="collapse" type="button">
								<i class="fa fa-minus"></i>
							</button>
						</div>
					</div>
					<div class="box-body">
		<div class="alert alert-success" id="message" style="display: none;">
			<button data-dismiss="alert" class="close">
				×
			</button>
			<span id="content">修改成功</span>
		</div>
		<fieldset>
		<div class="form-group row">
			<div class="col-sm-3">
			<div class="input-group">
				<input type="hidden" value="${expressStyle.id}" id="expressStyleId">
				<label for="pmsprinters_corpLevel" class="input-group-text">
					公司:
				</label>
				<input type="text" id="logisticsCompanyName"
					name="logisticsCompanyName"
					value="${expressStyle.logisticsCompany.companyName}"
					class="form-control input-large required" minlength="3" readOnly="true" />
			</div>
			</div>
			
			<div class="col-sm-3">
			<div class="input-group">
				<label for="pmsprinters_corpLevel" class="input-group-text">
					快递单名称:
				</label>
				<input type="text" id="expressStyleName" name="expressStyleName"
					value="${expressStyle.styleName}" class="form-control input-large required"
					minlength="3" />
				
			</div>
			</div>
			<script type="text/javascript">
	jQuery(document).ready(
			function() {
			var boxes = $("input[type='checkbox']",$("#selectNames"));
					    boxes.on("ifChanged", function(event){
							Moditify($(this));
						});
				jQuery("#button_btn")
						.click(
								function() {
									var content = getContent();
									var expressStyleName = $(
											"#expressStyleName").val();
									var checkDefault = "normal";
									
									var expressWidth = $("#expressWidth").val();
		var expressHeight = $("#expressHeight").val();
		if (!valNumber(expressWidth)) {
			alert("请填入正确的长度");
			$("#expressWidth").focus();
			return;
		} else {
			expressWidth = expressWidth * 100;
		}
		if (!valNumber(expressHeight)) {
			alert("请填入正确的宽度");
			$("#expressHeight").focus();
			return;
		} else {
			expressHeight = expressHeight * 100;
		}
									var temp = '&content=' + content
											+ '&expressStyleName='
											+ expressStyleName
											+ '&type=' + checkDefault+'&expressWidth='+expressWidth+'&expressHeight='+expressHeight;
									updateAjaxExpressStyle(temp);
								});
			});
	function updateAjaxExpressStyle(ajaxTempString) {
		
		$.ajax({
			type : 'post',
			url : '${ctx}/v2/expressPrinting/updateAjaxExpressStyle',
			data : 'expressStyleId=' + $("#expressStyleId").val()
					+ ajaxTempString,
			dataType : 'json',
			success : function(data) {
				    $("#content").html(data.content);
					$("#message").show();
				
			},
			error : function() {

			}
		});
	}
	function selectAjaxDesign() {
		$.ajax({
			type : 'post',
			url : '${ctx}/v2/expressPrinting/selectAjaxDesign',
			data : 'expressStyleId=' + '${expressStyle.id}',
			dataType : 'json',
			success : function(data) {
				if (data.status="1") {
					checkedData(data.content);
					DisplayDesign(data.content);
				}
			},
			error : function() {

			}
		});
	}
	function DisplayDesign(temp) {
		LODOP = getLodop(document.getElementById('LODOP2'), document
				.getElementById('LODOP_EM2'));
		eval(temp);
		//LODOP.SET_SHOW_MODE("SETUP_IN_BROWSE", 1);
		//LODOP.SET_SHOW_MODE("SETUP_ENABLESS", "11111111111000");
		//LODOP.PRINT_SETUP();
		LODOP.SET_SHOW_MODE("DESIGN_IN_BROWSE", 1);		
		LODOP.PRINT_DESIGN();
	};

	function Moditify(item) {
		LODOP = getLodop(document.getElementById('LODOP2'), document
				.getElementById('LODOP_EM2'));
		if (item.is(":checked")) {
			LODOP.ADD_PRINT_TEXTA(item.attr("name"), 56, 32, 175, 30, item.val());
		} else {
			LODOP.SET_PRINT_STYLEA(item.attr("name"), 'Deleted', !item.is(":checked"));
		}
	}
	function getContent() {
		LODOP = getLodop(document.getElementById('LODOP2'), document
				.getElementById('LODOP_EM2'));
		return LODOP.GET_VALUE("ProgramCodes", 0);

	};
	selectAjaxDesign();

	function checkedData(content) {
		var contents = content.split(";");
		for ( var i = 0; i < contents.length; i++) {
			var line = contents[i];
			if (line != null) {
				var index = line.indexOf("(");
				var end = line.indexOf(",");
				if (end != -1) {
					var indexString = line.substring(index + 2, end - 1);
					//$("input[name='" + indexString + "']").attr("checked", true);
					$("input[name='" + indexString + "']").iCheck('check');
				}
			}
		}
	}
</script>
	</div>
			
		</fieldset>
			<tags:printerLodop></tags:printerLodop>
			<div class="modal-footer bg-gray">
				<c:if test="${status eq 0 }">
					<input id="button_btn" class="btn btn-success" type="button"
						value="增加" />
				</c:if>
				<c:if test="${status eq 1 }">
					<input id="button_btn" class="btn btn-info" type="button"
						value="修改" />
				</c:if>
				&nbsp;
				<input id="cancel_btn" class="btn" type="button" value="返回"
					onclick="history.back()" />
		</div>
		</div>
		</div>
		</div>
		</div>
		</section>
	</body>
</html>
